package com.ibm.android.format;

import com.google.zxing.Result;
import com.ibm.android.validator.AmountValidator;
import com.ibm.android.validator.CurrencyValidator;
import com.ibm.android.validator.EmailValidator;
import com.ibm.android.validator.StringValidator;
import com.ibm.android.validator.TransactionValidator;



public class BusinessDataValidator {
	
	private String rawText;
	
	public BusinessDataValidator(String r) {
		this.rawText = r;//.getText();
	}
	
	public boolean validate() {
		if (rawText == null || !rawText.startsWith("BEGIN_INTUIT_INFORMATION")) {
	      return false;
	    }
		String[] fields = rawText.split(":-:");
		
		
		
		if (fields == null || fields.length == 0)  {
			return false;	
		}
		
		for(int i=0; i<fields.length; i++) {
			if (validateField(fields[i]) == false)
				return false;
		}
		
		return true;
	}
	
	public boolean validateField(String field) {
		if (field.startsWith("PRODUCT_NAME")) {
			return new StringValidator().isAValidInput(field.replaceFirst("PRODUCT_NAME:", ""));
		}
		else if (field.startsWith("PRODUCT_DESCRIPTION")) {
			return new StringValidator().isAValidInput(field.replaceFirst("PRODUCT_DESCRIPTION:", ""));
		}
		else if (field.startsWith("VENDOR_NAME")) {
			return new StringValidator().isAValidInput(field.replaceFirst("VENDOR_NAME:", ""));
		}
		else if (field.startsWith("EMAIL")) {
			return new EmailValidator().isAValidInput(field.replaceFirst("EMAIL:", ""));
		}
		else if(field.startsWith("AMOUNT")) {
			return new AmountValidator().isAValidInput(field.replaceFirst("AMOUNT:", ""));
		}
		else if (field.startsWith("CURRENCY")) {
			return new CurrencyValidator().isAValidInput(field.replaceFirst("CURRENCY:", ""));
		}
		else if (field.startsWith("TRANSACTION")) {
			return new TransactionValidator().isAValidInput(field.replaceFirst("TRANSACTION:", ""));
		}
		else if(field.startsWith("BEGIN_INTUIT_INFORMATION")) {
			return true;
		}
		else {
			return false;
		}
	}

}
